//
//  IdentitySelectView.m
//  Comma
//
//  Created by 刘轩博 on 15/1/17.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "IdentityRegisterView.h"
#import "LoginAndRegister.h"
#import "CollegeRegisterViewController.h"


#define PHOTO_WIDTH 100
#define PHOTO_X (SCREEN_WIDTH - 148 - PHOTO_WIDTH) / 2 + 74
@implementation IdentityRegisterView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/



#pragma mark - 职业&性别选择
- (void)createStudentAndSexButton
{
    self.frame = CGRectMake(0, 312, SCREEN_WIDTH, SCREEN_HEIGHT - 312);
    
    // 创建学生和性别的父视图
    self.stuSuperView = [[UIView alloc] initWithFrame:CGRectMake(74 + SCREEN_WIDTH, 156, 80, 21)];
    self.sexSuperView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * 2 - 74 - 80, 156, 80, 21)];
    [self addSubview:_stuSuperView];
    [self addSubview:_sexSuperView];
    
    
    // 选择学生按钮
    self.studentButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _studentButton.frame = CGRectMake(0, 0, 40, 16);
    [_studentButton setTitle:@"学生" forState:UIControlStateNormal];
    [_studentButton setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
    [_studentButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0f]];
    _studentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [_studentButton addTarget:self action:@selector(typeSelectAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.stuSuperView addSubview:_studentButton];
    
    // 选择教师按钮
    self.teacherButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _teacherButton.frame = CGRectMake(40, 0, 40, 16);
    [_teacherButton setTitle:@"教师" forState:UIControlStateNormal];
    [_teacherButton setTitleColor:TEXTERGRAY forState:UIControlStateNormal];
    [_teacherButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0f]];
    _teacherButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    // 点击事件
    [_teacherButton addTarget:self action:@selector(typeSelectAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.stuSuperView addSubview:_teacherButton];
    
    // 滑动的绿线
    self.studentLine = [[UIView alloc] initWithFrame:CGRectMake(0, 19, 32, 2)];
    _studentLine.backgroundColor = TEXTGREENCOLOR;
    [self.stuSuperView addSubview:_studentLine];
    
    // 创建灰线
    UIView *leftLine = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 80, 0.5)];
    leftLine.backgroundColor = LINEERGRAY;
    [self.stuSuperView addSubview:leftLine];
    
    // 选择男
    self.maleBtton = [UIButton buttonWithType:UIButtonTypeSystem];
    _maleBtton.frame = CGRectMake(0, 0, 40, 16);
    [_maleBtton setTitle:@"男" forState:UIControlStateNormal];
    [_maleBtton setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
    [_maleBtton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0f]];
    // 点击事件
    [_maleBtton addTarget:self action:@selector(typeSelectAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.sexSuperView addSubview:_maleBtton];
    
    // 选择女
    self.fmaleButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _fmaleButton.frame = CGRectMake(40, 0, 40, 16);
    [_fmaleButton setTitle:@"女" forState:UIControlStateNormal];
    [_fmaleButton setTitleColor:TEXTERGRAY forState:UIControlStateNormal];
    [_fmaleButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0f]];
    // 点击事件
    [_fmaleButton addTarget:self action:@selector(typeSelectAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.sexSuperView addSubview:_fmaleButton];
    
    // 滑动的绿线
    self.sexLine = [[UIView alloc] initWithFrame:CGRectMake(12, 19, 16, 2)];
    _sexLine.backgroundColor = TEXTGREENCOLOR;
    [self.sexSuperView addSubview:_sexLine];
    // 创建灰线
    UIView *rightLine = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 80, 0.5)];
    rightLine.backgroundColor = LINEERGRAY;
    [self.sexSuperView addSubview:rightLine];
    
    [self createLine];
}

#pragma mark - 分割线
- (void)createLine
{
    self.upLine = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 88, SCREEN_WIDTH, 0.5)];
    _upLine.backgroundColor = LINEERGRAY;
    [self addSubview:_upLine];
}

#pragma mark - 学生&教师,性别点击事件
- (void)typeSelectAction:(UIButton *)button
{
    if ([button.titleLabel.text isEqualToString:@"学生"]) {
        [_studentButton setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
        [_teacherButton setTitleColor:TEXTERGRAY forState:UIControlStateNormal];
        [UIView animateWithDuration:0.01 animations:^{
            _studentLine.frame = CGRectMake(0, 19, 32, 2); 
        }];
    }
    if ([button.titleLabel.text isEqualToString:@"教师"]) {
        [_studentButton setTitleColor:TEXTERGRAY forState:UIControlStateNormal];
        [_teacherButton setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
        [UIView animateWithDuration:0.01 animations:^{
            _studentLine.frame = CGRectMake(48, 19, 32, 2); 
        }];
    }

    if ([button.titleLabel.text isEqualToString:@"男"]) {
        [_maleBtton setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
        [_fmaleButton setTitleColor:TEXTERGRAY forState:UIControlStateNormal];
        [UIView animateWithDuration:0.01 animations:^{
            _sexLine.frame = CGRectMake(12, 19, 16, 2); 
        }];
    }

    if ([button.titleLabel.text isEqualToString:@"女"]) {
        [_maleBtton setTitleColor:TEXTERGRAY forState:UIControlStateNormal];
        [_fmaleButton setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
        [UIView animateWithDuration:0.01 animations:^{
            _sexLine.frame = CGRectMake(52, 19, 16, 2);         }];
    }
    
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:button.titleLabel.text, @"type", nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"IDENTITY" object:self userInfo:dic];
    
}


@end
